<?
$pagename=LA_WAP_NAV;
include_once("header_inc.php");
$catid_search = "";
$tplList=new TplLoad;
$val_string="";
$val_string2="";
/*JMR: validación de avisos no PAGOS */
if ($set_validation == 1) { $val_string = " AND ad_is_validated = 1  AND ad_enabled = 1"; } else { $val_string = " AND ad_enabled = 1"; }
if ($set_validation == 1) { $val_string2 = " where ad_is_validated = 1  AND ad_enabled = 1"; } else { $val_string2 = " AND ad_enabled = 1"; }

$sql_links = "select ad_id,ad_title,ad_description,ad_date from $ads_tbl $val_string2 order by ad_id desc limit 30";
$sql_result = q ($sql_links);
$num_links =  mysql_num_rows($sql_result);
$file_pointer = fopen("wap/index.wml", "w");
fwrite($file_pointer,"<?xml version=\"1.0\"?>\n"
. "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n"
. "<wml>\t<card id=\"LatestAds\" title=\"Latest ads\">\n<p><table columns=\"1\">");
fclose($file_pointer);

for ($i=0; $i<$num_links; $i++)
{
      $row = mysql_fetch_array($sql_result);
      $ad_id = $row["ad_id"];
      $sitetitle = $row["ad_title"];
      $ad_description = $row["ad_description"];
      $datestamp = $row["datestamp"];
      $ad_date=formatDateShort($row["ad_date"]);
      $fp=fopen("wap/index.wml", 'a');
      fwrite($fp,"\n<tr><td><a href=\"detail.wml#wap_$ad_id\">$sitetitle</a> $ad_date1</td></tr>");
      fclose($fp);
}

      $fi=fopen("wap/index.wml", 'a');
      fwrite($fi,"</table></p></card></wml>");
      fclose($fi);

$num_links =  mysql_num_rows($sql_result);


$sql_links = "select ad_id,ad_title,ad_description,user_name,user_email from $ads_tbl, $usr_tbl where ad_owner = user_id $val_string order by ad_id desc limit 10";
$sql_result = q ($sql_links);
$num_links =  mysql_num_rows($sql_result);

 for ($i=0; $i<$num_links; $i++)
 {
      $row = mysql_fetch_array($sql_result);
      $ad_id = $row["ad_id"];
      $sitetitle = $row["ad_title"];
      $ad_description = strip_tags($row["ad_description"]);
      $name = $row["user_name"];
      $phone = $row["phone"];
      $email = $row["user_email"];
      
      $array[] = "<card id=\"wap_$ad_id\" title=\"$sitetitle\"><p>$sitetitle<br />$ad_description<br /><br />$name / $email</p></card>";
}



$arrelm0=""; $arrelm1=""; $arrelm2=""; $arrelm3=""; $arrelm4=""; $arrelm5=""; $arrelm6=""; $arrelm7=""; $arrelm8=""; $arrelm9=""; $arrelm10="";
$special = "";

// DETAILED PAGES
$start = "<?xml version=\"1.0\"?>\n<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n<wml>\t";
if (isset($array[0]))
	$arrelm0 = $array[0];
if (isset($array[1]))
	$arrelm1 = $array[1];
if (isset($array[2]))
	$arrelm2 = $array[2];
if (isset($array[3]))
	$arrelm3 = $array[3];
if (isset($array[4]))
	$arrelm4 = $array[4];
if (isset($array[5]))
	$arrelm5 = $array[5];
if (isset($array[6]))
	$arrelm6 = $array[6];
if (isset($array[7]))
	$arrelm7 = $array[7];
if (isset($array[8]))
	$arrelm8 = $array[8];
if (isset($array[9]))
	$arrelm9 = $array[9];
if (isset($array[10]))
	$arrelm10 = $array[10];
$slutt= "</wml>";

$file_pointer = fopen("wap/detail.wml", "w");
fwrite($file_pointer,"$start $arrelm0 $arrelm1 $arrelm2 $arrelm3 $arrelm4 $arrelm5 $arrelm6 $arrelm7 $arrelm8 $arrelm9 $arrelm10 $slutt");
fclose($file_pointer);
$tplList->assign("wap_url","http://$set_url/wap/index.wml");
if (file_exists("images/rss.xml"))
	$tplList->assign("LA_RSS_FEED", LA_RSS_FEED);
$tplList->display("latestwap.tpl");
include_once("footer_inc.php");
?>
